package com.atguigu.admin.user.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.net.ssl.HttpsURLConnection;
import javax.servlet.http.HttpSession;

/**
 * @author durant
 * @create 2021-09-08 8:52
 */
@Controller
public class IndexController {

    @GetMapping(value = {"/","/login"})
    public String loginPage(){

        return "login";
    }
    @PostMapping("login")
    public String logincontroller(String username, String password, HttpSession session, Model model){
        if (username!=null&&"123".equals(password)){
            System.out.println(username);
            System.out.println(password);
            session.setAttribute("loginuser", username);

        return "redirect:/main.html";

        }else {
        model.addAttribute("msg", "账号密码错误");
        return "login";
        }
    }
    @GetMapping("/main.html")
    public String mainPage(HttpSession session,Model model){
        Object loginuser = session.getAttribute("loginuser");
        if (loginuser!=null){

        return "main";
        }else {
            model.addAttribute("msg", "没有登录,请勿跳过");
            return "login";
        }
    }
}
